<TITLE>BGI Documentation for 
registerbgidriver
</TITLE>
<H2>
registerbgidriver
</H2>
<HR>
<DL>


<DT><B>Syntax</B><DD>
<PRE>
#include &lt;graphics.h&gt;
int registerbgidriver(void (*driver)(void));
</PRE>



<DT><B>Description</B><DD>
registerbgidriver enables a user to load a driver file and "register" the driver. Once its memory location has been passed to registerbgidriver, initgraph uses the registered driver. A user-registered driver can be loaded from disk onto the heap, or converted to an .OBJ file (using BGIOBJ.EXE) and linked into the .EXE.
<P>
Calling registerbgidriver informs the graphics system that the driver pointed to by driver was included at link time. This routine checks the linked-in code for the specified driver; if the code is valid, it registers the code in internal tables.
<P>
By using the name of a linked-in driver in a call to registerbgidriver, you also tell the compiler (and linker) to link in the object file with that public name.

<P><DT><B>Return Value</B><DD>
registerbgidriver returns a negative graphics error code if the specified driver or font is invalid. Otherwise, registerbgidriver returns the driver number.
<P>
If you register a user-supplied driver, you must pass the result of registerbgidriver to initgraph as the driver number to be used.

<P><DT><B>Windows Notes <IMG SRC="win.gif" ALT="[WIN]"></B><DD>
registerbgidriver is not available in the <A HREF="../../bgi/README.html">winbgim</A> implementation.

<P><DT><B>See also</B>
<DD><A HREF="graphresult.html"> graphresult </A>
<DD><A HREF="initgraph.html"> initgraph </A>
<DD><A HREF="installuserdriver.html"> installuserdriver </A>
<DD><A HREF="registerbgifont.html"> registerbgifont </A>


<P><DT><B>Example</B><DD>
<PRE>
/* registerbgidriver example */ 

#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt;

int main(void)
{
   /* request autodetection */
   int gdriver = DETECT, gmode, errorcode;

   /* register a driver that was added into GRAPHICS.LIB */
   errorcode = registerbgidriver(EGAVGA_driver);

   /* report any registration errors */
   if (errorcode &lt; 0) {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();

      exit(1);               /* terminate with an error code */
   }

   /* initialize graphics and local variables */
   initgraph(&gdriver, &gmode, "");

   /* read result of initialization */
   errorcode = graphresult();
   if (errorcode != grOk) {  /* an error occurred */
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1);               /* terminate with an error code */
   }


   /* draw a line */
   line(0, 0, getmaxx(), getmaxy());

   /* clean up */
   getch();
   closegraph();
   return 0;
}
</PRE>



</DL>
<HR>
<A HREF="index.html">Back to index</A>
